package com.supcon.news.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.supcon.news.bean.News;
import com.supcon.news.dao.NewsDao;

public class NewsDaoImpl extends HibernateDaoSupport implements NewsDao
{
	public void saveNews(News news)
	{
		this.getHibernateTemplate().save(news);
	}

	@SuppressWarnings("unchecked")
	public List<News> findAllNews()
	{
		String hql = "from News news order by news.id desc";
		List<News> list = this.getHibernateTemplate().find(hql);
		return list;
	}

	public void deleteNews(News news)
	{
		this.getHibernateTemplate().delete(news);
	}

	public News findById(int id)
	{
		return this.getHibernateTemplate().get(News.class, id);
	}

	public void updateNews(News news)
	{
		System.out.println("news: id " + news.getId());
		this.getHibernateTemplate().update(news);
	}
}
